export default ({
	url,
	data,
	method = "GET",
	header = {
		"Content-Type": "application/json",
	}
}) => {
	return new Promise((resolve, reject) => {
		const token = uni.getStorageSync('token')
		let headered = {
			...header,
			"Authorization": token
		}
		uni.showLoading({
			title: "加载中"
		})
		const baseUrl = "http://localhost:8080"
		uni.request({
			url: baseUrl + url,
			data: data,
			method: method,
			header: headered,
			success: (res) => {
				if (res.data.code === 401) {
					uni.removeStorageSync('userMessage');
					uni.showToast({
						icon: "none",
						title: "登录已过期, 请重新登陆！",
						mask: true,
						duration: 3000
					})
					setTimeout(() => {
						uni.navigateTo({
							url: "/pages/login/login"
						})
					}, 2000)
				}
				if (res.data.code === 200) {
					resolve(res)
				}
				if (res.data.code !== 200) {
					uni.showToast({
						icon: "none",
						title: res.data.msg
					})
					reject(res)
				}
			},
			fail: (res) => {
				uni.showToast({
					icon: "none",
					title: "网络错误"
				})
				reject(res)
			},
			complete: () => {
				uni.hideLoading()
			}
		})
	})
}